package com.dcbeida.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.adapter.holder.BaseViewHolder;
import com.dcbeida.bean.LengthObj;
import com.dcbeida.utils.Utils;

import java.util.Random;

/**
 * 首页柱状图滑动列表
 */

public class GalleryAdapter extends ListAdapter<LengthObj> {


    public GalleryAdapter(Activity context) {
        super(context);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.gallery_item, parent, false);
        }
        View v_v1 = BaseViewHolder.get(convertView, R.id.v_v1);
        View v_v2 = BaseViewHolder.get(convertView, R.id.v_v2);
        TextView tvMonth = BaseViewHolder.get(convertView, R.id.tvMonth);
        if (position == mList.size() - 1) {
            tvMonth.setText(R.string.ben);
        } else {
            tvMonth.setText("" + (position + 1));
        }
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) v_v1.getLayoutParams();
        LinearLayout.LayoutParams params2 = (LinearLayout.LayoutParams) v_v2.getLayoutParams();
        LengthObj obj = mList.get(position);

        params.setMargins(0, obj.getLength(), 0, 0);
        params2.setMargins(0, obj.getLength2(), 0, 0);
        v_v1.setLayoutParams(params);
        v_v2.setLayoutParams(params2);
        return convertView;
    }


    private int calculateMargTop() {
        int all = Utils.convertDip2Pixel(112 - 10);
        Random random = new Random();
        return random.nextInt(all / 2);

    }

}
